package com.edu.compile.dto.calc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.edu.compile.dto.RequestParam;
import com.edu.model.constant.EventConstant;

import java.util.List;

public class CalcParam extends RequestParam<CalcParam> {
    /**
     * 0-固定值  1-来自节点
     *
     * @see EventConstant.SourceConstant#VAL
     * @see EventConstant.SourceConstant#FRO
     */
    private Integer source;

    /**
     * 0-数值型（默认） 1-布尔型 2-字符串 3-时间型
     *
     * @see EventConstant.ParamType
     */
    private Integer sourceType;

    /**
     * 1/<id@key>
     * 固定值
     * 来自节点
     */
    private String sourceValue;

    /**
     * 0-+ 1-- 2-* 3-/ 4-max 5-min 6-avg
     *
     * @see EventConstant#OperateSign
     */
    private Integer operateSign;

    private List<CalcTargetParam> targets;

    public CalcParam() {
    }

    @Override
    public CalcParam parse(String requestParam) {
        JSONObject jsonObject = JSON.parseObject(requestParam);
        this.source = jsonObject.getInteger("source");
        this.sourceType = jsonObject.getInteger("sourceType");
        this.sourceValue = jsonObject.getString("sourceValue");
        this.operateSign = jsonObject.getInteger("operateSign");
        String targetsJson = jsonObject.getString("targets");
        this.targets = JSON.parseObject(targetsJson, new TypeReference<List<CalcTargetParam>>() {
        }.getType());
        return this;
    }

    public Integer getSource() {
        return source;
    }

    public void setSource(Integer source) {
        this.source = source;
    }

    public Integer getSourceType() {
        return sourceType;
    }

    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    public String getSourceValue() {
        return sourceValue;
    }

    public void setSourceValue(String sourceValue) {
        this.sourceValue = sourceValue;
    }

    public Integer getOperateSign() {
        return operateSign;
    }

    public void setOperateSign(Integer operateSign) {
        this.operateSign = operateSign;
    }

    public List<CalcTargetParam> getTargets() {
        return targets;
    }

    public void setTargets(List<CalcTargetParam> targets) {
        this.targets = targets;
    }

}
